package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.VisitorInfoEntity;
import com.uchiha.nova.core.model.vo.VisitorInfoVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IVisitorInfoService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 访客表 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class VisitorInfoWrapper extends BaseEntityWrapper<VisitorInfoEntity, VisitorInfoVO>  {
  
  IVisitorInfoService visitorInfoService = SpringUtil.getBean(IVisitorInfoService.class);
  
	public static VisitorInfoWrapper build() {
		return new VisitorInfoWrapper();
 	}

	@Override
	public VisitorInfoVO entityVO(VisitorInfoEntity visitorInfoEntity) {
		VisitorInfoVO visitorInfoVO = new VisitorInfoVO();
		BeanUtil.copyProperties(visitorInfoEntity, visitorInfoVO);

		return visitorInfoVO;
	}
	public List<VisitorInfoVO> listVO(List<VisitorInfoEntity> list) {
		List<VisitorInfoVO> collect = list.stream().map(item -> {
            VisitorInfoVO visitorInfoVO = new VisitorInfoVO();
		    BeanUtil.copyProperties(item, visitorInfoVO);			
			return visitorInfoVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<VisitorInfoVO> pageVO(IPage<VisitorInfoEntity> pages) {
		IPage<VisitorInfoVO> page = pages.convert(item->{
            VisitorInfoVO visitorInfoVO = new VisitorInfoVO();
		    BeanUtil.copyProperties(item, visitorInfoVO);			
			return visitorInfoVO;
		});
		return page;
	}
}
